package com.victor9ac.tfm.mashup.uris;

import java.net.URI;
import java.net.URISyntaxException;

public class MashupURIFactory{

	URI uri;
	
	

	public MashupURIFactory(ConnectionBean connectionData, String resourceContext, String resourceRequested) {

		try {
			
			String port = connectionData.port != null && !"".equals(connectionData.port) ? (":"+connectionData.port) : "" ;
			
			String resource = resourceContext != null && !"".equals(resourceContext) ? resourceContext+"/" : "";
			
			String rsContext = connectionData.rsContext != null && !"".equals(connectionData.rsContext) ? connectionData.rsContext+"/" : "";
			
			uri = new URI(connectionData.protocol + "://" + connectionData.host
					+ port + "/"+connectionData.rsName+"/"+rsContext +resource + trimRequestedName(resourceRequested));
		} catch (URISyntaxException e) {
			System.out.println("uri bad build error");
			e.printStackTrace();
		}
		System.out.println(uri.toString());

	}
	public URI getUri(){
		return uri;
	}
	
	
	String trimRequestedName(String rq){
		rq = rq.trim();
		rq = rq.replaceAll(" ", "%20");
		return rq; 
		
		
	}

}
